<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="../static/easyui/jedate.min.js"></script>
<script type="text/javascript" src="../static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/easyui/themes/metro-orange/easyui.css">
<link rel="stylesheet" href="../static/easyui/themes/metro-red/window.css">
<link rel="stylesheet" href="../static/ttt/css/AddTrainingProject.css?<%=Math.random()%>">

<style type="text/css">

</style>
</head>
<body>
<script type="text/javascript">
$(function(){
var empids="";
$("#addProfectyuangong").hide();
$("#zhezao").hide();
$("#AddTrainingProject_tianshutext").attr("readonly",true);
	if($("#AddTrainingProject_jihuanametext").val()!=""){
		//培训名称
	     $("#AddTrainingProject_jihuanametext").attr("readonly",true);
		//培训地点
	     $("#AddTrainingProject_didiantext").attr("readonly",true);
		//计划天数
		 $("#AddTrainingProject_tianshutext").attr("readonly",true);
		//开始时间
		 $("#AddTrainingProject_strattiametext").attr("readonly",true);
		//结束时间
		 $("#AddTrainingProject_endtimetext").attr("readonly",true);
		//内容
		 $("#AddTrainingProject_TrainingContents").attr("readonly",true);
		//原因
		 $("#AddTrainingProject_TrainingReasons").attr("readonly",true);
		$("#TngPro_queding").text("提交");
	}
 	$('#AddTrainingProject_table').datagrid({    
		 //url:'AddTrainingProject_table', //数据源地址
	   columns:[[    
	   	{field:'RUSID',fixed:false,width:213,title:'课程编号'},    
	       {field:'RUSNAME',fixed:false,width:213,title:'课程名称'},    
	       {field:'EMPNAME',fixed:false,width:213,title:'培训老师'},
	       {field:'RUSTIME',fixed:false,width:213,title:'课程时长'},
	       {field:'caozuo',fixed:false,width:213,formatter:shanchu,title:'操作'} 
	       
			    
	   ]],
	   pagination:true,
	   pageNumber:1,
	   pageSize:5,
	   pageList:[5,10,15] 
	});  
	$("#xinzeng_xiangmukecheng").click(function(){
		$("#addTrainingProjectClass_win").window("open");
		$('#AddTrainingProjectClass_tables').datagrid({    
			 url:'TrainingCourse', //数据源地址
			 singleSelect: true,
		    columns:[[    
		    	{field:'RUSID',fixed:false,width:213,title:'课程编号',align:'center'},    
		        {field:'RUSNAME',fixed:false,width:213,title:'课程名称',align:'center'},    
		        {field:'EMPNAME',fixed:false,width:213,title:'培训老师',align:'center'},
		        {field:'JNXXNAME',fixed:false,width:213,title:'培训技能',align:'center'},
		        {field:'RUSTIME',fixed:false,width:213,title:'课程时长',align:'center'},
		        {field:'RUSDATE',fixed:false,width:213,title:'创建日期',align:'center',
		        	formatter : function(value){
		        		var d = new Date(value);
		        		var times=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
		        		return times;
		        	}
		        } ,
		        {field:'caozuo',fixed:false,width:213,formatter:operate_formatter,title:'操作',align:'center'} 
		        
				    
		    ]],
		    pagination:true,
		    pageNumber:1,
		    pageSize:5,
		    pageList:[5,10,15]  
		}); 
		
	});
	//计算日期
	$("#AddTrainingProject_tianshutext").click(function(){
		if($("#AddTrainingProject_strattiametext").val()!=""&&$("#AddTrainingProject_endtimetext").val()!=""){
			//开始时间
			var planninds=$("#AddTrainingProject_strattiametext").val();
			//结束时间
			var planmaxds=$("#AddTrainingProject_endtimetext").val();
			var DateStart = new Date(planninds);
			var DateEnd = new Date(planmaxds);
			var moth=0;
			moth=(DateEnd.getMonth() - DateStart.getMonth())
			var plant = (DateEnd.getDate() - DateStart.getDate())
			if(moth==0){
				$("#AddTrainingProject_tianshutext").val(plant+1);
			}else if(moth>0){
				$("#AddTrainingProject_tianshutext").val((plant+1)+moth*30);
			}else if(moth<0){
				$("#addTrainingPlan_win_daystext").val("");
				plant="";
			}
			$("#AddTrainingProject_tianshutext").attr("readonly",true);
			//"Personnel"alert($("#AddTrainingProject_tianshutext").val())
			if($("#AddTrainingProject_tianshutext").val()<=1){
				alert("培训天数不能少于1天，请核对您的开始时间与结束时间，谢谢!");
				$("#AddTrainingProject_tianshutext").val("");
				plant="";
				
			}else if($("#AddTrainingProject_tianshutext").val()>60){
				alert("培训天数不能大于60天，请核对您的开始时间与结束时间，谢谢!");
				$("#AddTrainingProject_tianshutext").val("");
				plant="";
				
			}
			
		}else{
			$.messager.show({
				title:'信息提示',
				msg: '请填写开始时间与结束时间',
				timeout:1500,  //1秒后消失
				showType:'slide',//弹出的方式。类似ppt里的图片弹出方式
				//弹出框的样式。居中显示
				style:{
					right:'',
					top:document.body.scrollTop+document.documentElement.scrollCenter,
					bottom:''
				}
			});
		}
	})
	$("#TngPro_queding").click(function(){
		//培训课程编号
		var kechengId=$("#AddTrainingProject_table").datagrid("getRows"); 
		var ClassId="";
		for(var i=0;i<kechengId.length;i++){
			ClassId+=kechengId[i].RUSID+","
		}
		var empid=$("#empids_").val();
		if($("#TngPro_queding").text()=="确定"){
		//培训名称
		var planname=$("#AddTrainingProject_jihuanametext").val();
		//培训地点
		var plandd=$("#AddTrainingProject_didiantext").val();
		//计划天数
		var plants=$("#AddTrainingProject_tianshutext").val();
		//开始时间
		var planninds=$("#AddTrainingProject_strattiametext").val();
		//结束时间
		var planmaxds=$("#AddTrainingProject_endtimetext").val();
		//内容
		var plannr=$("#addPaymentt_win_TrainingContents").val();
		//原因
		var planyy=$("#AddTrainingProject_TrainingReasons").val();
		var myDate = new Date();
		var DateStart = new Date(planninds);
		var moth=(myDate.getMonth()+1);
		var date=myDate.getDate()
		
/* 		alert("本月："+moth)
		alert("选择月份："+(DateStart.getMonth()+1))
		fxgf
		alert("本月日期："+date)
		alert("选择日期："+(DateStart.getDate()+1)) */
		var DATE_FORMAT = /^[0-9]{4}-[0-1]?[0-9]{1}-[0-3]?[0-9]{1}$/;

		/* if((DateStart.getMonth()+1)<moth||(DateStart.getMonth()+1)>=moth&&DateStart.getDate()<date){
			alert("开始时间不能低于/等于今天")
		}else */ if(planname==""){
	 		alert("培训名称为空")
	 	}else if(plandd==""){
	 		alert("培训地点为空")
	 	}else if(planninds==""){
	 		alert("培训开始时间为空")
	 	}else if(planmaxds==""){
	 		alert("培训结束时间为空")
	 	}else if(plants==""){
	 		alert("培训天数为空")
	 	}else if(empid==""){
	 		alert("请添加培训人员")
	 	}else if(ClassId==""){
	 		alert("请添加培训课程")
	 	}else{
	 		if(DATE_FORMAT.test(planninds)&&DATE_FORMAT.test(planmaxds)){
		 		$.ajax({
					type:"post",
					url:'Add_projects', //数据源地址
					data:{
						planname:planname,
						plandd:plandd,
						plants:plants,
						planninds:planninds,
						planmaxds:planmaxds,
						plannr:plannr,
						planyy:planyy,
						plants:plants,
						ClassId:ClassId,
						empid:empid
					},
					success: function(data){ 
						empids="";
						close("新增培训项目");
						plan_tables();
						//add("培训项目","ttt/training-project");
					}
					
				}) 
	 		}else{
	 			alert("您的日期输入有误，请重新输入！")
	 		}
	 	}
		}else if($("#TngPro_queding").text()=="提交"){
			//培训计划id
			var planid=$("#planid").val();
			if(empid==""){
		 		alert("请添加培训人员")
		 	}else if(ClassId==""){
		 		alert("请添加培训课程")
		 	}else{
				$.ajax({
					type:"post",
					url:'adds_pojs', //数据源地址
					data:{
						planid:planid,
						ClassId:ClassId,
						empid:empid
					},
					success: function(data){ 
						empids="";
						close("新增培训项目");
						add("培训计划","ttt/training-plan");
					}
					
				}) 
		 	}
		}

	})
	$("#AddTrainingProject_xueyuantext").click(function(){
		//$("#addProfectyuangong").window("open");
		$("#addProfectyuangong").show();
		$("#zhezao").show();
		$("#yuan_tree").tree({
			checkbox:true,
			onlyLeafCheck:true,
			url:"Profect_zhijiEmp"
		})
	})
	$("#Profectyuangong_queding").click(function(){
		var nodes = $('#yuan_tree').tree('getChecked', ['checked','indeterminate']);
		var empname=[];
		for (var i = 0; i < nodes.length; i++) {

			//获取三级功能id，存入数
			empids+=nodes[i].id+",";
			empname.push(nodes[i].text);

		}
		//empname.splice(empname[0],1);
		$("#AddTrainingProject_xueyuantext").val(empname);
		$("#empids_").val(empids)
		$("#addProfectyuangong").hide();
		$("#zhezao").hide();
	})
	$("#TngPro_quxiao").click(function(){
		close("新增培训项目");
	})
})
//在每个操作列里面添加编辑，查看，明细，删除
function shanchu(value, row, index) {
return "<span class='spanclass'>删除</span> ";
}
function operate_formatter(value, row, index) {
	return "<span class='spanclass' onclick='tianjias()'>添加</span>";
}
function tianjias(){
	var kechengId=$("#AddTrainingProject_table").datagrid("getRows"); 
	if(kechengId.length==0){
		var rows=$("#AddTrainingProjectClass_tables").datagrid("getChecked");
		var row={
				RUSID:rows[0].RUSID,
				RUSNAME:rows[0].RUSNAME,
				EMPNAME:rows[0].EMPNAME,
				RUSTIME:rows[0].RUSTIME
		}
		$('#AddTrainingProject_table').datagrid('appendRow',row);
		$("#addTrainingProjectClass_win").window("close");
	}else{
		alert("您已添加过课程")
	}

}

</script>
<div id="zhezao">

</div>
 <div id="addProfectyuangong">
	<!-- <table id="Profect_yuangong" style="width:100%;height:300px"data-options="fitColumns:true">
	
	</table>   -->
	<div style="width:400px;height:335px;margin:0px auto;">
		<ul id="yuan_tree" style="width:400px;height:335px;margin:0px auto;border-bottom:1px solid #d4a375;overflow:auto;"></ul>
	</div>
	<button id="Profectyuangong_queding">确定</button>
</div>
<div id="AddTrainingProject_bigbox">
		<div id="AddTrainingProject_box" class="addTrainingPlan_win_box">
			<a id="AddTrainingProject_jihuaname" class="addTrainingPlan_win_text" style="">计划名称：</a>
			<input id="AddTrainingProject_jihuanametext" value="${PlanAll.planname }"class="addTrainingPlan_win_textswidth" type="text"/>
				<input type="hidden" id="planid" value="${PlanAll.planid}" />
		</div>
		<div id="AddTrainingProject_box2" class="addTrainingPlan_win_box">
			<a id="AddTrainingProject_strattiame" class="addTrainingPlan_win_text" style="">开始时间：</a>
<!-- 			<input id="AddTrainingProject_strattiametext" class="addTrainingPlan_win_textswidth" type="text" required ="required"/>
 -->			<input id="AddTrainingProject_strattiametext" value="${PlanAll.plannind}" style="width:220px;height:25px;"class="easyui-datebox addTrainingPlan_win_texts" type="text"  required ="required"/>
			
		</div>
		<div id="AddTrainingProject_box3" class="addTrainingPlan_win_box margins_left">
			<a id="AddTrainingProject_endtime" class="addTrainingPlan_win_text" style="">结束时间：</a>
<!-- 			<input id="AddTrainingProject_endtimetext" class="addTrainingPlan_win_textswidth" type="text"  required ="required"/>
 -->			<input id="AddTrainingProject_endtimetext" value="${PlanAll.planmaxd}" style="width:220px;height:25px;" class="easyui-datebox addTrainingPlan_win_texts" type="text"  required ="required"/>
		</div>
		<div id="AddTrainingProject_box_1"style="margin-bottom:-40px;" class="addTrainingPlan_win_box">
			<a id="AddTrainingProject_didian" class="addTrainingPlan_win_text" style="">培训地点：</a>
			<input id="AddTrainingProject_didiantext" value="${PlanAll.plandd }"class="addTrainingPlan_win_textswidth" type="text"/>
		</div>
		<div id="AddTrainingProject_box_2" style="margin-top:20px;"class="addTrainingPlan_win_box margins_left">
			<a id="AddTrainingProject_tianshu" class="addTrainingPlan_win_text" style="">培训天数：</a>
			<input id="AddTrainingProject_tianshutext" value="${PlanAll.plants}" class="addTrainingPlan_win_textswidth" type="text"/>
		</div>
		 <div id="AddTrainingProject_box4" style="margin-top:20px;"class="addTrainingPlan_win_box margins_left">
			<a id="AddTrainingProject_TrainingContentss" class="addTrainingPlan_win_text" style="">培训内容：</a>
			<textarea cols="50" rows="10" id="AddTrainingProject_TrainingContents"  style="width:220px"  class="AddTrainingProjecttext"  type="text">${PlanAll.plannr}</textarea>
		</div>
		<div id="AddTrainingProject_box5" class="addTrainingPlan_win_box">
			<a id="AddTrainingProject_TrainingReasonss" class="addTrainingPlan_win_text" style="">培训原因：</a>
			<textarea cols="50" rows="10" id="AddTrainingProject_TrainingReasons"  class="AddTrainingProjecttext" type="text">${PlanAll.planyy}</textarea>
		</div> 
		<div id="AddTrainingProject_box8" class="addTrainingPlan_win_box">
			<a id="AddTrainingProject_xueyuan" class="addTrainingPlan_win_text" style="">培训学员：</a>
			<textarea cols="50" rows="10"  id="AddTrainingProject_xueyuantext" class="AddTrainingProjecttext" type="text"></textarea>
			<input type="hidden" id="empids_">
		</div> 
		<div id="AddTrainingProject_box9">
			<div id="addTrainingProjectClass_win" class="easyui-window" title="添加培训课程" style="width:600px;height:400px"
			    		data-options="resizable: false,draggable:false,closed:true,minimizable:false,maximizable:false,collapsible:false">
					<table id="AddTrainingProjectClass_tables" class="easyui-datagrid" style="width:100%;height:100%;" data-options="fitColumns:true">
					
					</table>
			 </div>
			<button id="xinzeng_xiangmukecheng">添加课程</button>
		</div>
		<div style="width:1035px;float:left;margin-left:15px;">
			<table id="AddTrainingProject_table" class="easyui-datagrid" style="width:100%;height:250px;" data-options="fitColumns:true">
					
			</table>
		</div>
		<div id="box7y">
			<button id="TngPro_queding" style="margin-right:15px;">确定</button>
			<button id="TngPro_quxiao">取消</button>
		</div>
</div>
</body>
</html>